// pages/set/set.js
const app = getApp()
import { HTTP } from '../../utils/https.js'
var util = require('../../utils/util.js');
let http = new HTTP()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inforChecked: true,
    lianxiChecked: false,
    phone:Number, //手机号
    is_weixin:Number,//是否绑定微信
    showpopup:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      phone: options.phone,
      is_weixin: options.weixin,
      inforChecked: options.is_material == '0' ? false : true,
      lianxiChecked: options.is_contact == '0' ? false : true
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return util.share()
  },
 //退出登录
    submit:function(){
      var that = this;
      http.request({
        url: 'mini/v1/login/logout',
        success: function (res) {
          wx.removeStorageSync('token');
          wx.removeStorageSync('region_name');
          wx.removeStorageSync('checklogin');
          wx.removeStorageSync('checkcity');
          wx.removeStorageSync('region_id');
          wx.removeStorageSync('code');
          wx.reLaunch({
            url: '../login/login'
          })
        }
      })
    },
  //绑定手机号
    getPhoneNumber: function (e) {
      if (e.detail.encryptedData) {
        //var that = this;
        //const data = { code: this.data.code, iv: e.detail.iv, encryptedData: e.detail.encryptedData };
        console.log('888')
      }
    },
  //个人信息显示
   switchinfor:function(e){
     var is_material = e.detail.value == true ? '1' : '0';
     var data = {};
     if (e.currentTarget.dataset.type == 'conact'){
       data = { is_contact: is_material}
     }else{
       data = { is_material: is_material }
     }
     var that = this;
     http.request({
       url: 'mini/v1/personal/info_patch',
       methods:'post',
       data: data,
       success: function (res) {
       }
     })
  },
  showif:function(e){
    this.setData({
      phone: e.detail.phone,
      showpopup:1
    })
  },
  bind_phone:function(){
    this.setData({
      showpopup: 0
    })
  }
  
})